import math

def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def closest_prime_number(num):
    if not num.isdigit() or len(num) != 3:
        print("Wrong input")
        return
    number = int(num)
    if is_prime(number):
        print(number)
        return
    lower = number
    upper = number
    while not is_prime(lower) and not is_prime(upper):
        lower -= 1
        upper += 1
    while not is_prime(lower):
        lower -= 1
    while not is_prime(upper):
        upper += 1
    if is_prime(lower):
        print(lower)
    else:
        print(upper)

words = input("Enter three words: ").lower().split()
numbers = {'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'}
num = ''.join([numbers[word] for word in words])
closest_prime_number(num)
